#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> front, back, ret;
        front.resize(nums.size(), 1);
        ret.resize(nums.size(), 1);
        back.resize(nums.size(), 1);

        for (int i = 1; i < nums.size(); i++) front[i] = front[i - 1] * nums[i - 1];
        for (int i = nums.size() - 2; i >= 0; i--) back[i] = back[i + 1] * nums[i + 1];
        for (int i = 0; i < nums.size(); i++) ret[i] = front[i] * back[i];

        return ret;
    }
};